package test;

import com.ucpaas.restDemo.client.JsonReqClient;

public class TestYunzx {

	public static void main(String[] args) {
		String appkey = "b17147607caa70bfa48736dbd965ff7b";
		String secret = "af1da084acc03baf2f13b16c21dd9481";
		String appId = "21fbcdb14c6242959a0bcbbb2ad712ad";
		String tel = "15001236918";
		String code = "5678";
		String product = "SMS测试服务";
		
		TestYunzx test = new TestYunzx();
		boolean b1 =test.sendCodeSms(appkey, secret, appId, "33368", tel, code, product);
		boolean b2 =test.sendCodeVoice(appkey, secret, appId, tel, code);
		boolean b3 =test.sendSms(appkey, secret, appId, "34466", tel, new String[]{"h16","2016-12-20 10:10:10","开发者网站许可操作相关测试"});
		System.out.println(b1+" "+b2+" "+b3);
	}

	public boolean sendCodeSms(String appkey, String secret, String appId, String template, String tel, String code,
			String product) {
		boolean b = false;
		try {
			JsonReqClient client = new JsonReqClient();
			String result = client.templateSMS(appkey, secret, appId, template, tel, code + "," + product);
			if (result.contains("\"respCode\":\"000000\"")) {
				b = true;
			} else {
			}
		} catch (Exception e) {
		}
		return b;
	}

	public boolean sendCodeVoice(String appkey, String secret, String appId, String tel, String code) {
		boolean b = false;
		try {
			JsonReqClient client = new JsonReqClient();
			String result = client.voiceCode(appkey, secret, appId, tel, code);
			if (result.contains("\"respCode\":\"000000\"")) {
				b = true;
			} else {
			}
		} catch (Exception e) {
		}
		return b;
	}

	public boolean sendSms(String appkey, String secret, String appId, String template, String tel, String[] txtary) {
		boolean b = false;
		try {
			StringBuilder sb = new StringBuilder();
			for (String s : txtary) {
				sb.append(s);
				sb.append(",");
			}
			String code = sb.toString();
			if (code.length() > 1) {
				code = code.substring(0, code.length() - 1);
			}
			// 多个参数的情况
			JsonReqClient client = new JsonReqClient();
			String result = client.templateSMS(appkey, secret, appId, template, tel, code);
			if (result.contains("\"respCode\":\"000000\"")) {
				b = true;
			} else {
			}
		} catch (Exception e) {
		}
		return b;
	}
}
